package com.gosuncn.controller;

import com.gosuncn.pojo.OmsNodeInfo;
import com.gosuncn.service.OmsNodeService;
import com.gosuncn.tools.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 监控信息
 * @author zxl
 * @date 2021/8/3
 */
@RestController
@RequestMapping("/oms")
public class OmsNodeController {



    @Autowired
    private OmsNodeService omsNodeService;

    /**
     * 查询记录
     * @return  list所有数据
     */
    @GetMapping("/getAllOmsNode")
    public String getAllOmsNode(){
        List<OmsNodeInfo> omsNodeInfos = omsNodeService.selectList();
        return "查询成功";
    }

    /**
     *根据id查询记录
     * @return
     */
    @GetMapping("/getOmsNodeById/{id}")
    public String getOmsNodeById(@PathVariable Integer id){
        OmsNodeInfo omsNodeInfo = omsNodeService.findOmsNodeById(id);
        if (omsNodeInfo!=null) {
            return "查询成功";
        }
        return "查询失败";

    }


    /**
     * 添加记录
     * @return
     */
    @PostMapping("/addOmsNode")
    public String addOmsNode(@RequestBody OmsNodeInfo omsNodeInfo){
        Boolean flag = omsNodeService.insert(omsNodeInfo);
        if (flag) {
            return "添加成功";
        }
        return "添加失败";
    }


    /**
     * 更新记录
     * @return
     */
    @PutMapping("/updateOmsNode")
    public String updateOmsNode(@RequestBody OmsNodeInfo omsNodeInfo){
        Boolean flag =omsNodeService.updateById(omsNodeInfo);
        if (flag) {
            return "更新成功";
        }
        return "更新失败";
    }


    /**
     * 通过id删除记录
     * @param id
     * @return
     */
    @DeleteMapping("/deleteOmsNode/{id}")
    public String deleteOmsNode(@PathVariable int id){
        Boolean flag = omsNodeService.deleteById(id);
        if (flag) {
            return "删除成功";
        }
        return "删除失败";
    }


}
